<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- 选中一段内容，点击按钮复制选中的内容 -->
</head>
<body>
    <p id="text">这是要复制的内容</p>
    <input id="input">
    <button onclick="copyText()">copy</button>
  <script>
    function copyText() {
        var text = document.getElementById("text").innerText;
        var input = document.getElementById("input");
        input.value = text; // 修改文本框的内容
        input.select(); // 选中文本
        document.execCommand("copy"); // 执行浏览器复制命令
        alert("复制成功");
      }
  </script>
</body>
</html>